<script setup lang="ts">
import {onMounted, ref} from 'vue'
import {loadConfig, setConfig} from './api'
import {ElMessage} from 'element-plus'
import {KillExplorer, Reboot, StartExplorer} from '../../../wailsjs/go/view/App'
import VapHost from './VapHost.vue'

let old = {
  rdpPort: 0,
  startForPath: false,
  multiSession: false,
  noNetworkAuth: false,
  avgCPU: false,
  oldRdp: false,
  hideDisk: false,
  disabledDisk: false,
  hideNavigation: false,
  disabledRightClick: false,
}

const checkBoxList = ref({
  rdpPort: false,
  startForPath: false,
  multiSession: false,
  noNetworkAuth: false,
  avgCPU: false,
  oldRdp: false,
  hideDisk: false,
  disabledDisk: false,
  hideNavigation: false,
  disabledRightClick: false,
})
const rdpPort = ref(3389)

onMounted(() => {
  ElMessage({
    message: "注意：该配置工具仅适用于 windows server 系统。",
    type: 'warning',
  })
  loadHostConfig()
})

const loadHostConfig = async () => {
  old = await loadConfig()
  rdpPort.value = old.rdpPort
  checkBoxList.value.startForPath = old.startForPath
  checkBoxList.value.multiSession = old.multiSession
  checkBoxList.value.noNetworkAuth = old.noNetworkAuth
  checkBoxList.value.avgCPU = old.avgCPU
  checkBoxList.value.oldRdp = old.oldRdp
  checkBoxList.value.hideDisk = old.hideDisk
  checkBoxList.value.disabledDisk = old.disabledDisk
}

const clickExecBut = () => {
  setConfig(old, checkBoxList.value, rdpPort.value)
}

const clickDefaultBut = () => {
  checkBoxList.value = {
    rdpPort: true,
    startForPath: true,
    multiSession: false,
    noNetworkAuth: true,
    avgCPU: true,
    oldRdp: true,
    hideDisk: true,
    disabledDisk: false,
    hideNavigation: false,
    disabledRightClick: false,
  }
  rdpPort.value = 3389
}

const vapHostRef = ref()
const clickVapHostBtn = () => {
  vapHostRef.value.showDialog()
}
</script>

<template>
  <div class="h-full">
    <VapHost ref="vapHostRef"></VapHost>
    <div class="inline-block w-full">
      <div class="flex">
        <el-card class="w-1/2 inline-block">
          <template #header>
            <div>
              <span>远程桌面服务</span>
            </div>
          </template>
          <div>
            <div class="flex">
              <el-checkbox v-model="checkBoxList.rdpPort"> RDP默认端口： </el-checkbox>
              <el-input v-model="rdpPort" placeholder="名称" class="w-4" />
            </div>
            <div>
              <el-checkbox v-model="checkBoxList.startForPath">
                允许以绝对路径启动远程应用程序
              </el-checkbox>
            </div>

            <div>
              <el-checkbox v-model="checkBoxList.noNetworkAuth">
                不使用网络级别的身份验证
              </el-checkbox>
            </div>
            <div>
              <el-checkbox v-model="checkBoxList.avgCPU"> 平均分配CPU资源 </el-checkbox>
            </div>
            <div>
              <el-checkbox v-model="checkBoxList.oldRdp">
                向下兼容旧版本 RDP (server 2008R2及以前的版本)</el-checkbox
              >
            </div>
            <div>
              <el-checkbox v-model="checkBoxList.multiSession" disabled>
                允许用户开启多会话配置(需要RD支持)
              </el-checkbox>
            </div>
            <div>
              <el-checkbox disabled> 将RDP端口添加到防火墙白名单</el-checkbox>
            </div>
            <div>
              <el-checkbox disabled> 关闭防火墙(建议仅虚拟机环境开启)</el-checkbox>
            </div>
          </div>
        </el-card>
        <div></div>
        <el-card class="w-1/2 inline-block">
          <template #header>
            <div>
              <span>主机资源服务</span>
            </div>
          </template>
          <div>
            <el-checkbox v-model="checkBoxList.hideDisk"> 隐藏主机磁盘A-H(仅隐藏) </el-checkbox>
          </div>
          <div>
            <el-checkbox v-model="checkBoxList.disabledDisk">
              隐藏主机磁盘A-H(同时限制访问)
            </el-checkbox>
          </div>
          <div>
            <el-checkbox disabled> 关闭左侧导航栏(家庭组、库、网络、快速访问...) </el-checkbox>
          </div>
          <div>
            <el-checkbox disabled> 禁用"非应用区"右键菜单 </el-checkbox>
          </div>
          <div>
            <el-checkbox disabled> 将WEBDAV服务纳入防火墙白名单 </el-checkbox>
          </div>
        </el-card>
      </div>
    </div>
    <div class="inline-block h-[20%] w-full">
      <div class="flex">
        <el-card class="w-full inline-block">
          <template #header>
            <div>
              <span>通用配置</span>
            </div>
          </template>
          <div>
            <div class="flex-wrap">
              <el-button @click="clickDefaultBut">一键助选(默认推荐)</el-button>
              <el-button @click="loadHostConfig">重新加载</el-button>
              <el-button @click="clickExecBut">执行策略</el-button>
              <el-button @click="Reboot">重启主机</el-button>
            </div>
            <el-divider content-position="left">备用</el-divider>
            <div class="flex-wrap">
              <el-button @click="KillExplorer">资源管理器(关闭)</el-button>
              <el-button @click="StartExplorer">资源管理器(启动)</el-button>
              <el-button @click="clickVapHostBtn">设置vapHost</el-button>
            </div>
          </div>
        </el-card>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped></style>
